#include "SpiInterface.h"

void SpiTransmitReceiveByte( SPI_HandleTypeDef* spi, uint8_t* txData, uint8_t* rxData ) {
    HAL_SPI_TransmitReceive( spi, txData, rxData, 1, 0xffff );
}

void SpiTransmitByte( SPI_HandleTypeDef* spi, uint8_t* txData ) {
    HAL_SPI_Transmit( spi, txData, 1, 0xffff );
}

void SpiReceiveByte( SPI_HandleTypeDef* spi, uint8_t* rxData ) {
    HAL_SPI_Receive( spi, rxData, 1, 0xffff );
}

void SpiTransmitReceiveByteDMA( SPI_HandleTypeDef* spi, uint8_t* txData, uint8_t* rxData ) {
    HAL_SPI_TransmitReceive_DMA( spi, txData, rxData, 1 );
    while ((HAL_SPI_GetState( spi ) != HAL_SPI_STATE_READY));
}





void SpiTransmitReceive( SPI_HandleTypeDef* spi, uint8_t* txData, uint8_t* rxData, uint16_t len ) {
    HAL_SPI_TransmitReceive( spi, txData, rxData, len, 0xffff );
}

void SpiTransmit( SPI_HandleTypeDef* spi, uint8_t* txData, uint16_t len ) {
    HAL_SPI_Transmit( spi, txData, len, 0xffff );
}

void SpiReceive( SPI_HandleTypeDef* spi, uint8_t* rxData, uint16_t len ) {
    HAL_SPI_Receive( spi, rxData, len, 0xffff );
}

#if 1

void SpiReceiveByteDMA( SPI_HandleTypeDef* spi, uint8_t* rxData ) {
    HAL_SPI_Receive_DMA( spi, rxData, 1 );
    while ((HAL_SPI_GetState( spi ) != HAL_SPI_STATE_READY));
}

void SpiTransmitByteDMA( SPI_HandleTypeDef* spi, uint8_t* txData ) {
    HAL_SPI_Transmit_DMA( spi, txData, 1 );
    while ((HAL_SPI_GetState( spi ) != HAL_SPI_STATE_READY));
}

void SpiTransmitReceiveDMA( SPI_HandleTypeDef* spi, uint8_t* txData, uint8_t* rxData, uint16_t len ) {
    HAL_SPI_TransmitReceive_DMA( spi, txData, rxData, len );
    while ((HAL_SPI_GetState( spi ) != HAL_SPI_STATE_READY));
}

void SpiTransmitDMA( SPI_HandleTypeDef* spi, uint8_t* txData, uint16_t len ) {
    HAL_SPI_Transmit_DMA( spi, txData, len );
    while ((HAL_SPI_GetState( spi ) != HAL_SPI_STATE_READY));
}

void SpiReceiveDMA( SPI_HandleTypeDef* spi, uint8_t* rxData, uint16_t len ) {
    HAL_SPI_Receive_DMA( spi, rxData, len );
    while ((HAL_SPI_GetState( spi ) != HAL_SPI_STATE_READY));
}

#else

void SpiReceiveByteDMA( SPI_HandleTypeDef* spi, uint8_t* rxData ) {
    HAL_SPI_Receive( spi, rxData, 1, 0xffff );
}

void SpiTransmitByteDMA( SPI_HandleTypeDef* spi, uint8_t* txData ) {
    HAL_SPI_Transmit( spi, txData, 1, 0xffff );
}
void SpiTransmitReceiveDMA( SPI_HandleTypeDef* spi, uint8_t* txData, uint8_t* rxData, uint16_t len ) {
    HAL_SPI_TransmitReceive( spi, txData, rxData, len, 0xffff );
}

void SpiTransmitDMA( SPI_HandleTypeDef* spi, uint8_t* txData, uint16_t len ) {
    HAL_SPI_Transmit( spi, txData, len, 0xffff );
}

void SpiReceiveDMA( SPI_HandleTypeDef* spi, uint8_t* rxData, uint16_t len ) {
    HAL_SPI_Receive( spi, rxData, len, 0xffff );
}

#endif


